﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Adrr.Model;
namespace Adrr.BLL
{
	/// <summary>
	/// SecretKey_ID
	/// </summary>
	public partial class SecretKey_ID
	{
		private readonly Adrr.DAL.SecretKey_ID dal=new Adrr.DAL.SecretKey_ID();
		public SecretKey_ID()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid SecretKey)
		{
			return dal.Exists(SecretKey);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Adrr.Model.SecretKey_ID model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Adrr.Model.SecretKey_ID model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid SecretKey)
		{
			
			return dal.Delete(SecretKey);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string SecretKeylist )
		{
			return dal.DeleteList(SecretKeylist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Adrr.Model.SecretKey_ID GetModel(Guid SecretKey)
		{
			
			return dal.GetModel(SecretKey);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Adrr.Model.SecretKey_ID GetModelByCache(Guid SecretKey)
		{
			
			string CacheKey = "SecretKey_IDModel-" + SecretKey;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(SecretKey);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Adrr.Model.SecretKey_ID)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Adrr.Model.SecretKey_ID> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Adrr.Model.SecretKey_ID> DataTableToList(DataTable dt)
		{
			List<Adrr.Model.SecretKey_ID> modelList = new List<Adrr.Model.SecretKey_ID>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Adrr.Model.SecretKey_ID model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Adrr.Model.SecretKey_ID();
					if(dt.Rows[n]["SecretKey"]!=null && dt.Rows[n]["SecretKey"].ToString()!="")
					{
						model.SecretKey=new Guid(dt.Rows[n]["SecretKey"].ToString());
					}
					if(dt.Rows[n]["EnterpriserID"]!=null && dt.Rows[n]["EnterpriserID"].ToString()!="")
					{
					model.EnterpriserID=dt.Rows[n]["EnterpriserID"].ToString();
					}
					if(dt.Rows[n]["AssignTo"]!=null && dt.Rows[n]["AssignTo"].ToString()!="")
					{
					model.AssignTo=dt.Rows[n]["AssignTo"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

